package com.econ.powercloud.ems.service.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.econ.powercloud.ems.dal.entity.IotProductJh;
import com.econ.powercloud.ems.dal.mapper.IotProductJhMapper;
import com.mysql.cj.util.StringUtils;
import org.springframework.stereotype.Repository;

/**
 * @Author : zjf
 * @Description :
 * @Date : 2022/11/17 11:21
 * @Modified by : zjf
 */
@Repository
public class IotProductJhDAO extends ServiceImpl<IotProductJhMapper, IotProductJh> {

    public Page<IotProductJh> selectPageBySearch(String productKey, String moduleCode, String search, Integer pageNo, Integer pageSize){
        LambdaQueryWrapper<IotProductJh> lambdaQuery = Wrappers.lambdaQuery();
        lambdaQuery.eq(IotProductJh::getProductKey,productKey);
        lambdaQuery.eq(IotProductJh::getModuleCode,moduleCode);
        lambdaQuery.and(!StringUtils.isNullOrEmpty(search), wrapper -> wrapper.like(IotProductJh::getDit, search).or().like(IotProductJh::getName, search));
        Page<IotProductJh> page = new Page<>(pageNo, pageSize);
        return this.baseMapper.selectPage(page,lambdaQuery);
    }
}
